var vm_jieyujingfeishoukuan = new Vue({
    el: "#jieyujingfeishoukuan",
    data: {
        deptid: $("#deptid").val(),		// 单位ID
        jigoujibie: $("#jigoujibie").val(),

        tuikuanlist: [],// 退款list
        piliangshoukuanlist:'', //批量收款list

        tuikuanitemid:'',

        piliangshoukuanids: [],//退款ids

        shoukuanzhuangtai:0, //收款状态
        deptName:'',  //单位名称
        tktime1:'',//退款开始时间
        tktime2:'',//退款结束时间

        chakan:{
            zhuanjianame:'',
            deptname:''
        },

        tuikuanMonthList:[],//退款详情列表

        pageindex: 1,		// 查询分页初始化页
        pagesize: 10,		// 查询分页初始化页面大小
        pageCount: 0,		// 总页数
        recordCount: 0,	// 总记录数
        targetpage: '', 	// 目标页

    },
    created: function () {
        var _this = this;
        _this.bindTuikuanList();
    },
    watch: {
        //监控分页情况，刷新列表
        pageindex: function () {
            this.bindTuikuanList();
        },

        pagesize: function () {
            //
            this.bindTuikuanList();
        },
        shoukuanzhuangtai : function(){
            this.bindTuikuanList();
        }
    },
    methods: {

        //查询下级单位退款计划列表
        bindTuikuanList: function () {
            var _this = this;
            $.post('/system/tuikuanjilu/shoukuanlist', {
                deptid: _this.deptid,
                deptname:_this.deptName,
                status : _this.shoukuanzhuangtai,
                tktime1:_this.tktime1,
                tktime2:_this.tktime2,
                pageindex: _this.pageindex,
                pagesize: _this.pagesize
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.tuikuanlist = data.shoukuanlist;
                        var pageInfo = data.PageInfo;
                        _this.pageindex = pageInfo.pageIndex;
                        _this.pageCount = pageInfo.pageCount;
                        _this.recordCount = pageInfo.recordCount;
                        _this.targetpage = '';
                    } else {
                        layer.alert(ppData.message)
                    }
                }
            }, "json");
        },
        getDate_tk:function(){
            var _this = this;
            _this.tktime1=$("#tktime1").val();
            _this.tktime2=$("#tktime2").val();
        },
        bindTuikuanMonthList: function (id) {
            var _this = this;
            $.post('/system/zhiliu/findZhiliuByTuikuanjiluId', {
                tuikuanjiluid: id,
                xingming: _this.chakan.zhuanjianame,
                deptname: _this.chakan.deptname
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.tuikuanMonthList = data;
                    } else {
                        layer.alert(ppData.message)
                    }
                }
            }, "json");
        },
        toChakan: function (id) {
            var _this = this;
            _this.tuikuanitemid = id
            _this.bindTuikuanMonthList(id)
            $("#chakanModalLabel2").html("退款详情");
            // $("#modal-dialog").attr("style","width:1200px;");
            $("#chakanModal2").modal();
        },
        toShoukuan: function () {
            var _this = this;

            var chk_value =[];

            _this.piliangshoukuanlist = [];
            _this.piliangshoukuanids = '';

            $('input[name="checkbox"]:checked').each(function(){
                chk_value.push($(this).val());
            });
            if (chk_value.length==0){
                layer.alert('您还没有选择任何退款！');
            }else{
                for(var i=0;i<chk_value.length;i++){
                    for(var j=0;j<_this.tuikuanlist.length;j++){
                        if (chk_value[i]==_this.tuikuanlist[j].id){
                            _this.piliangshoukuanlist.push(_this.tuikuanlist[j]);
                            _this.piliangshoukuanids = _this.piliangshoukuanids+_this.tuikuanlist[j].id+",";
                        }
                    }
                }
                $("#piliangModalLabel").html("批量收款");
                $("#modal-dialog").attr("style","width:1200px;");
                $("#piliangshoukuanModal").modal();
            }
        },
        Shoukuan:function (id) {
            var _this = this;
            $.modal.confirm("是否确认收款",function () {
                    $.post('/system/jisuan/tuikuanshoukuan', {
                        jiluid: id,
                    }, function (ppData) {
                        if (ppData != null) {
                            if (ppData.result == 1) {
                                layer.open({
                                    time: 1000,
                                    btn: [],
                                    content: "确认退款成功!",
                                });
                                _this.refresh();
                            } else {
                                layer.alert(ppData.message);
                            }
                        }
                    }, "json");
            }
            )
        },

        refresh:function(){
            var _this = this;
            _this.bindTuikuanList();
        },

        Daochu:function () {
            var _this = this;
            // 获取需要传递的参数值
            let deptId = _this.deptid; // 替换成实际的值
            let status = _this.shoukuanzhuangtai; // 替换成实际的值
            let deptname = _this.deptName; // 替换成实际的值
            let tktime1 = _this.tktime1; // 替换成实际的值
            let tktime2 = _this.tktime2; // 替换成实际的值

            // 构建接口URL
            var apiUrl = "/export/zhiliujinExport?deptId=" + deptId + "&status=" + status + "&deptname=" + deptname + "&tktime1=" + tktime1 + "&tktime2=" + tktime2;
            // 使用location.href跳转到接口
            location.href = apiUrl;

        },
        reset:function(){
            var _this = this;
            _this.shoukuanzhuangtai = 0;
            _this.deptName = '';
            _this.tktime1 = '';
            _this.tktime2 = '';
            _this.bindTuikuanList()
        },

        //全选按钮的点击事件
        checkAll(){
            //获取id的dom元素
            let Id = document.getElementById('allAndNotAll');
            //获取类名为chBox的dom元素
            let chBox = document.getElementsByName('checkbox');
            let len = chBox.length;
            //输出观察

            for(let i=0;i<len;i++){
                //当全选按钮为true时，全部按钮都为true，否则相反
                if(Id.checked){
                    chBox[i].checked=true;
                }
                else {
                    chBox[i].checked=false;
                }
            }
        },
        //单个按钮的点击事件
        checkOne(){
            let count=0;
            let chBox = document.getElementsByName('checkbox');
            let len = chBox.length;
            for(let i=0;i<len;i++){
                //记录单选按钮为true的数量
                if(chBox[i].checked){
                    count++;
                }
            }
            //当单选按钮都为true时，全选按钮也为true，否则为false
            if(count==len){
                document.getElementById('allAndNotAll').checked = true;
            }else {
                document.getElementById('allAndNotAll').checked = false;
            }
        },
        chakan_search:function () {
            var _this = this;
            _this.bindTuikuanMonthList(_this.tuikuanitemid);
        },
        chakan_search_reset:function () {
            var _this = this;
            _this.chakan.deptname=''
            _this.chakan.zhuanjianame=''
            _this.bindTuikuanMonthList(_this.tuikuanitemid);
        },
        //首页
        firstPage: function () {
            this.pageindex = 1;
        },
        //尾页
        lastPage: function () {
            this.pageindex = this.pageCount;
        },
        //上一页
        prePage: function () {
            var prePage = ((this.pageindex - 1) <= 0) ? 1 : (this.pageindex - 1);
            this.pageindex = prePage;
        },
        //下一页
        nextPage: function () {
            var nextPage = ((this.pageindex + 1) >= this.pageCount) ? this.pageCount : (this.pageindex + 1);
            this.pageindex = nextPage;
        },
        //跳到目标页
        targetPage: function () {
            if (this.targetpage != '' && this.targetpage <= this.pageCount && this.targetpage > 0) {
                this.pageindex = this.targetpage;
                this.targetpage = '';
            }
        },

    },
})